package com.example.copa_america;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.copa_america.dao.DataServiceNoticias;
import com.example.copa_america.model.Noticia;
import com.example.copa_america.model.Sede;

public class Noticias extends ListActivity {
	/** Called when the activity is first created. */
	
	private MyAdapter mAdapter = null;
	//private static ArrayList<Noticia> noticias;
	private static final String URL_TEST_NOTICIAS = "http://192.168.0.101/Ultima/proyecto2/noticias.xml";
	public static ArrayList<Noticia> noticias;
	DataServiceNoticias dataServiceNoticias = new DataServiceNoticias();
	ArrayList<Noticia> noticias2 = dataServiceNoticias.getNoticias(URL_TEST_NOTICIAS);
	

	public void onCreate(Bundle savedInstanceState) {
		//Intent startingIntent = getIntent();
		
		super.onCreate(savedInstanceState);
		//setContentView(R.layout.main2);
		
		
		//TextView textoNuevo = (TextView)findViewById(R.id.mostradornoticias);
		//textoNuevo.setText(noticias.get(1).getTexto().toString());
		noticias = noticias2;
		mAdapter = new MyAdapter(this);
		setListAdapter(mAdapter);
		
		
		
		}
		
		
		
		public static class MyAdapter extends BaseAdapter{
			
			private Context mContext;
			
			public MyAdapter(Context c){
				mContext = c;
			}
			
			@Override
			//especifica el numero de items
			public int getCount() {
				// TODO Auto-generated method stub
				return noticias.size();
			}

			@Override
			public Object getItem(int position) {
				// TODO Auto-generated method stub
				return noticias.get(position);
			}

			@Override
			public long getItemId(int position) {
				// TODO Auto-generated method stub
				return 0;
			}
			//devuelve las vistas
			@Override
			public View getView(int position, View convertView, ViewGroup parent) {
				
				View view = null;
				if(convertView==null){
					LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
					view = inflater.inflate(R.layout.listanoticias, null);
				} else {
					view = convertView;
				}
				
				TextView titulo = (TextView) view.findViewById(R.id.textView1);
				titulo.setText(noticias.get(position).getTexto());
				
				return view;
			}
			
		}
	
	
	
	
	
	
}